home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / GraphicsWrap / Source / generator.psw < prev    next >
Text File  |  1991-09-18  |  4KB  |  163 lines

  1. /*    Qix2.psw - the funky screen-saver.
  2.         -- this one is a "triangle"
  3.  
  4.     Written by Bill Spitzak, July 1989
  5.     Modified Dec, 1990 by Jiro Nakamura for System 2.0 and 
  6.         Cassandra support
  7.  
  8.     To compile:
  9.     pswrap -a -o qix.c qix.psw
  10.     cc -O -o qix qix.c -ldpsclient_p -lstreams_p
  11.     rm qix.c
  12. */
  13.  
  14. #include <dpsclient/dpsclient.h>    /* lets you do DPS calls */
  15. #include <math.h>
  16.  
  17. defineps desksize(|float * x,* y)
  18.     deskWin currentwindowbounds y x pop pop
  19. endps
  20.  
  21. defineps overlaywindow(int x,y)
  22.     0 0 x y Nonretained window
  23.     dup false exch setsendexposed
  24.     windowdeviceround
  25.     setexposurecolor
  26.     20 currentwindow setwindowlevel 
  27.     Above 0 currentwindow orderwindow
  28.     Mousemovedmask Keydownmask add Flagschangedmask add
  29.     currentwindow seteventmask
  30.     0.0 setlinewidth
  31.     hidecursor
  32. endps
  33.  
  34. defineps line(float width, color,x,y,x2,y2)
  35.     color setgray
  36.     x y moveto x2 y2 lineto stroke
  37. endps
  38.  
  39. defineps curve(float width,color,x,y,x2,y2,x3,y3,x4,y4)
  40.     width setlinewidth
  41.     color setgray
  42.     x y moveto x2 y2 x3 y3 x4 y4 curveto stroke
  43. endps
  44.  
  45. defineps showcursor()
  46.     showcursor
  47. endps
  48.  
  49. #define NUMLINES 200
  50. #define PI 3.1415926
  51.  
  52. main(int argc, char **argv) {
  53.     int p,n,erase;
  54.     float x1[NUMLINES],y1[NUMLINES],x2[NUMLINES],y2[NUMLINES],
  55.           x3[NUMLINES],y3[NUMLINES],x4[NUMLINES],y4[NUMLINES],
  56.           x5[NUMLINES],y5[NUMLINES],x6[NUMLINES],y6[NUMLINES],
  57.           x7[NUMLINES],y7[NUMLINES],x8[NUMLINES],y8[NUMLINES],
  58.     t1[NUMLINES],t2[NUMLINES],t3[NUMLINES],
  59.     p1,p2,p3,
  60.     xs,ys, xf,yf,
  61.     x1d,y1d,x2d,y2d,x3d,y3d,x4d,y4d,
  62.     x5d,y5d,x6d,y6d,x7d,y7d,x8d,y8d,
  63.     urx,ury,pmx,pmy, midx, midy, t,
  64.     s1,s2,s3;
  65.     int up=1, i;
  66.     DPSContext theDPSContext;
  67.     NXEvent e;
  68.  
  69.     theDPSContext = DPSCreateContext(0,0,0,0);
  70.     DPSSetContext(theDPSContext);
  71.     desksize(&urx,&ury);
  72.     overlaywindow(urx,ury);
  73.  
  74.     midx=urx/2;
  75.     midy=ury/2;
  76. //    fprintf(stderr, "(midx, midy): (%f,%f)\n", midx, midy);
  77.  
  78.     n = 0;
  79.     t = 0;
  80.     
  81.     // phases of the three points;
  82.     p1=0;
  83.     p2=(4*PI)/3;
  84.     p3=(2*PI)/3;
  85.  
  86.     // starting angle of each point;
  87.     t1[0]=0;
  88.     t2[0]=p2;
  89.     t3[0]=p3;
  90.  
  91.     s1=0;s2=0;s2=0;
  92. s1=1.0;
  93.     fprintf(stdout, "bgcolor 0 0 50\n");
  94.     fprintf(stdout, "fgcolor 255 255 255\n");
  95.     fprintf(stdout, "bgnpoly\n");
  96.  
  97.  
  98.     midx=319; midy=239;
  99.     for (i=0;i<80;i++) {
  100.       if (DPSGetEvent(theDPSContext,&e,-1,0.0,0)) {
  101.         
  102.         /* Since we are using it as a screensaver, remove this "safety" feature
  103.            if (e.type == NX_MOUSEMOVED) {
  104.            if (pmx && abs((int)(pmx-e.location.x))
  105.            +abs((int)(pmy-e.location.y)) > 8) break;
  106.            pmx = e.location.x; pmy = e.location.y;
  107.            }
  108.            else 
  109.            */            
  110.         break;
  111.       }
  112.       
  113.       // draw shit here;
  114.  
  115.       p=n; n=(n+1)%(NUMLINES-1);
  116.       erase=(n-(NUMLINES*.8)); if(erase<0) erase+=(NUMLINES-1);
  117. //      fprintf(stderr, "n=%d, p=%d, e=%d, nl=%d\n", n, p,
  118. //          erase,(int) (NUMLINES*.8));
  119.       if(n>(NUMLINES-1))n=0;
  120. /*      if(up){
  121.         s1+=0.001;
  122.         if(s1>=1.0) {
  123.           s1=1.0;
  124.           up=0;
  125.         }
  126.       } else {
  127.         s1-=0.007;
  128.         if(s1<=0.0) {
  129.           s1=0.0;
  130.           up=1;
  131.         }
  132.       } */
  133.  
  134.       t1[n]=t1[p]+0.008; if(t1[n]>(2*PI)) t1[n]-=(2*PI);
  135.       t2[n]=t2[p]+0.1; if(t2[n]>(2*PI)) t2[n]-=(2*PI);
  136.       t3[n]=t3[p]+0.05; if(t3[n]>(2*PI)) t3[n]-=(2*PI);
  137.       t-=0.3; if(t<0)t+=(2*PI);
  138. //      t+=0.5; if(t>(2*PI))t-=(2*PI);
  139.       
  140.       x1[n]=(cos(t3[n])*(s1*200))+midx;//+(cos(t)*70);
  141.       y1[n]=(sin(t1[n])*(s1*200))+midy;//+(sin(t)*70);
  142.       x2[n]=(cos(t2[n])*(s1*200))+midx;//+(cos(t)*70);
  143.       y2[n]=(sin(t2[n])*(s1*200))+midy;//+(sin(t)*70);
  144.       x3[n]=(cos(t1[n])*(s1*200))+midx;//+(cos(t)*70);
  145.       y3[n]=(sin(t3[n])*(s1*200))+midy;//+(sin(t)*70);
  146.  
  147.       line(0.0, 0.0, x1[erase], y1[erase], x2[erase], y2[erase]);
  148.       line(5.0, 1.0, x1[n], y1[n], x2[n], y2[n]);
  149.       fprintf(stdout, "vertex %d %d\n", (int)x2[n], (int)y2[n]);
  150.       line(0.0, 0.0, x2[erase], y2[erase], x3[erase], y3[erase]);
  151.       line(5.0, 1.0, x2[n], y2[n], x3[n], y3[n]);
  152.       fprintf(stdout, "vertex %d %d\n", (int)x3[n], (int)y3[n]);
  153.       line(0.0, 0.0, x3[erase], y3[erase], x1[erase], y1[erase]);
  154.       line(5.0, 1.0, x3[n], y3[n], x1[n], y1[n]);
  155.       fprintf(stdout, "vertex %d %d\n", (int)x1[n], (int)y1[n]);
  156.     }
  157.         fprintf(stdout, "endpoly");
  158.         showcursor();
  159.         DPSWaitContext(theDPSContext);
  160.         DPSDestroyContext(theDPSContext);
  161.       }
  162.     
  163.